<form class="form-horizontal">
		  <div class="modal-dialog" role="document">
		    <div class="modal-content">
		     <div class="modal-header">
		        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
		        <h4 class="modal-title" id="myModaLabel">${_res["systemManage.resignPrivilege"]}</h4>
		      </div>
		      <input type="hidden"  id="role_id" name="frontPrivilege.roleid" >
		      <div class="modal-body">
					<div class="partentDivWrap">
						<div class="content_wrap">
							<div class="zTreeDemoBackground left">
								<ul id="menu_tree" class="ztree"></ul>
							</div>
						</div>          
					</div>
		      </div>
		      <div class="modal-footer">
		        <button type="button" class="btn btn-warning" data-dismiss="modal">${_res["system.return"]}</button>
		        <%if(hasPrivilegeUrl("frontPrivlegeUpdate")){%>
		        <button type="button" class="btn btn-primary" onClick="submitPrivilege()">${_res["system.save"]}</button>
		        <%}%>
		      </div>
		    </div>
		  </div>
</form>



<script type="text/javascript">

		$(document).ready(function(){
			initTreeData();
		});
		
		var menuzTreeObj;// 树对象   
		var menuzNodes;// 树节点，
		var setting = {
			check: {
				enable: true
			},
			data: {
				simpleData: {
					enable: true
				}
			},
			view: {
				showIcon: false
			}
		};

		
		/* zhengshikang  树形checkboxTree加载  */
		function initTreeData() {
			$('#myModal').on('show.bs.modal', function(event) {
				var button = $(event.relatedTarget); // Button that triggered the modal
				var roleId = button.data('whatever'); // Extract info from data-* attributes
				var roleName = button.parents("tr").find("td").eq(1).text();
				var modal = $(this);
				modal.find('.modal-title').text('${_res["systemManage.resignPrivilege"]}  ( ' + roleName + ' )');
				$("#role_id").val(roleId);
				var url = "${cxt!}/platform/frontPrivlege/list/" + roleId;
				$.ajax({
					url : url,
					type : "get",
					dataType : "json",
					contentType:"application/json",
					success : function(data) {
						menuzNodes = data.menuNodes;
						menuzTreeObj = $.fn.zTree.init($("#menu_tree"), setting, menuzNodes);
					}
				});
				
				
			})
		}
		
		
		/* 提交角色 分配的权限 */
		function submitPrivilege(){
			var roleId = $("#role_id").val();
			var resourceIds = getCheckedValues();
			if(resourceIds==""){
				alert("请选择对应的菜单");
			}else{
				var url = "${cxt!}/platform/frontPrivlege/update?roleId=" + roleId+"&resourceIds="+resourceIds;
				$.ajax({
					url : url,
					type : "get",
					dataType : "json",
					success : function(data) {
						if(data.result){
							$("#myModal").modal('hide');
							alert("权限分配成功");
						}
					}
				});			
			}
		}
		
		//获得选中的权限
		function getCheckedValues() {
			var values = "";
			for ( var i = 0, j = menuzNodes.length; i < j; i++) {
				var nodes = menuzTreeObj.getNodeByParam("id", menuzNodes[i].id,null);
				console.log("==="+JSON.stringify(nodes)+"----");
				if (nodes.checked == true) {
					if (values == "") {
						values = nodes.id;
					} else {
						values = values + "," + nodes.id;
					}
				}
			}
			console.log("***********"+values+"***********");
			var valuesIds = encodeURI(values);
			return valuesIds;
		}
		
</script>